package com.noble.meether.fragment.mail.panel;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.noble.library.view.base.BasePanel;
import com.noble.meether.R;
import com.noble.meether.chat.ui.imui.util.IMChatUtil;
import com.noble.meether.fragment.mail.bean.UserMessage;
import com.noble.meether.fragment.mail.listener.UpdateMsgListListener;

import java.util.List;

/**
 * 用户聊天消息列表
 * Created by Su on 2018/7/30.
 */
public class MailMsgPanel extends BasePanel implements UpdateMsgListListener {
    private RecyclerView msg_list;
    private MailMsgAdapter msgAdapter;
    private List<UserMessage> msgList;

    private boolean isFirst = true;

    public MailMsgPanel(Context context) {
        super(context);
        setContentView(R.layout.mail_msg_panel);
        initView();
    }

    private void initView() {
        msg_list = (RecyclerView) findViewById(R.id.msg_list);
        msg_list.setLayoutManager(new LinearLayoutManager(getContext()));
        msg_list.setNestedScrollingEnabled(false);
        msgAdapter = new MailMsgAdapter(getActivity());
        msg_list.setAdapter(msgAdapter);

        IMChatUtil.getInstance().setUpdateMsgListListener(this);
    }

    @Override
    public void refreshMsgList() {
        msgList = IMChatUtil.getInstance().getMsgDBList();
        msgAdapter.setList(msgList);
    }

    public void refreshList() {
        if (isFirst) {
            msgList = IMChatUtil.getInstance().getMsgDBList();
            msgAdapter.setList(msgList);
            isFirst = false;
        }
    }
}
